package com.game;



import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;

public class MyClient
{
	public static void main(String[] args) throws IOException
	{
		Socket s = new Socket("127.0.0.1", 6677);


		String fileName = "D:\\ScanDemo.apk";
		File file = new File(fileName);
		FileInputStream is = new FileInputStream(fileName);

		OutputStream os = s.getOutputStream();
		try
		{
			int length = (int) file.length();

			writeFileContent(is, os, length);
			Thread.sleep(1000);

			BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
			String content = null;
			while ((content = br.readLine()) != null)
			{
				if (content.equals(file.length()+""))
				{
					System.out.println(content+ " -- Done");
				}
			}
		}
		catch (Exception e)
		{
			// TODO: handle exception
		}
		finally
		{
			os.close();
			is.close();
		}
	}

	private static void writeFileContent(InputStream is, OutputStream os,
			int length) throws IOException
	{
		
		byte[] buffer = new byte[4096];
		int size;
		while ((size = is.read(buffer)) != -1)
		{
			os.write(buffer, 0, size);
		}
	}
}
